﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WinFormsUI.Docking;

using ChaSQLite.SQLiteManage;
using ChaSQLite.Constants;

namespace ChaSQLite.SubForm
{
    public partial class DDLViewer : DockContent
    {
        private string title = "DDL Viewer";

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        public DDLViewer()
        {
            InitializeComponent();
        }

        private void DDLViewer_Load(object sender, EventArgs e)
        {
            this.Text = "DDL [" + title + "]";
            this.TabText = Text;

            getDDL();
        }

        private void getDDL()
        {
            DataTable table = SQLManager.getInstance.GetBase.ExecuteQuery(
                                        "SELECT sql FROM sqlite_master WHERE tbl_name = '" + title +"'"
                                        + "ORDER BY type DESC" );
            if (table.Columns.Count == 0)
                return;

            string sql = null;
            ddlText.Text = "";
            foreach (DataRow row in table.Rows)
            {
                foreach (DataColumn column in table.Columns)
                {
                    sql = row[column].ToString();
                    if ( sql.Length > 10 )
                        ddlText.Text += sql + ";\n\n";
                }
            }
            
        }

    }
}
